import Vue from 'vue'

export function u2d (value) {
  if (value !== undefined) {
    return Vue.moment.unix(value).format('YYYY-MM-DD')
  } else {
    return ''
  }
}

export function u2dt (value) {
  if (value !== undefined) {
    return Vue.moment.unix(value).format('YYYY-MM-DD HH:mm:ss')
  } else {
    return ''
  }
}

export function startTimestamp (val) {
  val = val | 0
  return parseInt(
    Vue.moment()
      .day(val)
      .set({ hour: 0, minute: 0, second: 0 })
      .format('X')
  )
}

export function endTimestamp (val) {
  val = val | 0
  return parseInt(
    Vue.moment()
      .day(val)
      .set({ hour: 23, minute: 59, second: 59 })
      .format('X')
  )
}

export function u2dtTableFormatter (row, column) {
  const value = row[column.property]
  if (value !== undefined) {
    return Vue.moment.unix(value).format('YYYY-MM-DD HH:mm:ss')
  } else {
    return '暂无数据'
  }
}

export function u2dTableFormatter (row, column) {
  const value = row[column.property]
  if (value !== undefined) {
    return Vue.moment.unix(value).format('YYYY-MM-DD')
  } else {
    return '暂无数据'
  }
}
